package com.decent.ejfadmin.equity.price.dao.provider;

import com.decent.ejfadmin.equity.common.CardPriceInfo;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;

/**
 * describe:权益密价配置SQL
 *
 * @author zhangbin
 * @date 2019/03/19
 */

public class SetCardPriceDaoProvider {

    public String updateCardPrice(HashMap<String, CardPriceInfo> map) {
        StringBuilder sql = new StringBuilder(200);
        CardPriceInfo cardPriceInfo = map.get("cardPriceInfo");
        sql.append(" UPDATE yuhuang_user_product_price p \n" +
                "SET p.modify_time = now( ),\n" +
                "p.admin = #{cardPriceInfo.admin},\n" +
                "p.max_price = #{cardPriceInfo.minPrice},\n" +
                "p.min_price = #{cardPriceInfo.minPrice}," +
                "p.xianyu_price = #{cardPriceInfo.xianyuPrice} \n" +
                "WHERE\n" +
                "  p.user_id IN ( '");
        sql.append(StringUtils.join(cardPriceInfo.getUserIds(), "','")).append("') ");
        sql.append("  AND p.product_id IN ( ");
        sql.append(StringUtils.join(cardPriceInfo.getProductIds(), ",")).append(" ) ");
        return sql.toString();
    }


    public String deleteCardPrice(HashMap<String, CardPriceInfo> map) {
        StringBuilder sql = new StringBuilder(200);
        CardPriceInfo cardPriceInfo = map.get("cardPriceInfo");
        sql.append(" DELETE \n" +
                "FROM\n" +
                "  yuhuang_user_product_price  \n" +
                "WHERE\n" +
                "  user_id IN ('");
        sql.append(StringUtils.join(cardPriceInfo.getUserIds(), "','"));
        sql.append("') AND product_id IN ( ");
        sql.append(StringUtils.join(cardPriceInfo.getProductIds(), ",")).append(" ) ");
        return sql.toString();
    }

    public String updateCardModelPrice(HashMap<String, Object> map) {
        StringBuilder sql = new StringBuilder(200);
        CardPriceInfo cardPriceInfo = (CardPriceInfo) map.get("cardPriceInfo");
        String equityModel = (String) map.get("equityModel");
        sql.append(" UPDATE yuhuang_supply_model_price_map p \n" +
                "SET p.modified_time = now( ),\n" +
                "p.admin = #{cardPriceInfo.admin},\n" +
                "p.max_price = #{cardPriceInfo.minPrice},\n" +
                "p.min_price = #{cardPriceInfo.minPrice}\n" +
                "WHERE\n" +
                "  p.model_id = #{equityModel} ");
        sql.append("  AND p.product_id IN ( ");
        sql.append(StringUtils.join(cardPriceInfo.getProductIds(), ",")).append(" ) ");
        return sql.toString();
    }

    public String deleteCardModelPrice(HashMap<String, CardPriceInfo> map) {
        StringBuilder sql = new StringBuilder(200);
        CardPriceInfo cardPriceInfo = map.get("cardPriceInfo");
        sql.append(" DELETE \n" +
                "FROM\n" +
                "  yuhuang_supply_model_price_map  \n" +
                "WHERE\n" +
                "  model_id = #{equityModel} ");
        sql.append("  AND product_id IN ( ");
        sql.append(StringUtils.join(cardPriceInfo.getProductIds(), ",")).append(" ) ");
        return sql.toString();
    }
}
